package com.cskaoyan.controller.front;

import com.cskaoyan.bean.po.CommonData;
import com.cskaoyan.bean.po.MarketAddress;
import com.cskaoyan.bean.vo.back.BaseRespVo;
import com.cskaoyan.service.front.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 地址管理
 * @auther 10-何兴绕
 * @Date 2022年10月13日 22:42
 */
@RestController
@RequestMapping("wx/address")
public class AddressController {

    @Autowired
    AddressService addressService;

    /**
     * 获取地址
     *
     * @return
     */
    @GetMapping("list")
    public BaseRespVo showAddress() {
        CommonData commonData = addressService.showAddress();
        return BaseRespVo.ok(commonData);
    }

    /**
     * 保存地址
     *
     * @return
     */
    @PostMapping("save")
    public BaseRespVo saveAddress(@RequestBody MarketAddress marketAddress) {
        Integer id = addressService.addAddress(marketAddress);
        return BaseRespVo.ok(id);
    }

    /**
     * 回显地址
     *
     * @return
     */
    @GetMapping("detail")
    public BaseRespVo echoAddress(Integer id) {
        MarketAddress marketAddress = addressService.echoAddress(id);
        return BaseRespVo.ok(marketAddress);
    }

    /**
     * 逻辑删除地址
     * @param marketAddress
     * @return
     */
    @PostMapping("delete")
    public BaseRespVo deleteAddress(@RequestBody MarketAddress marketAddress) {
        addressService.deleteAddress(marketAddress);
        return BaseRespVo.ok();
    }
}
